package com.creditrank.indexer;
import java.io.File;
import java.io.IOException;

import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.LockObtainFailedException;
import org.apache.lucene.util.Version;


public class MergeIndex 
{
	
	FSDirectory d1,d2,d3,d4,d5;
	{
	try {
		d1=FSDirectory.open(new File("Nag/index1"));
		d2=FSDirectory.open(new File("Nag/index2"));
		d3=FSDirectory.open(new File("Nag/index3"));
		d4=FSDirectory.open(new File("Nag/index4"));
		d5=FSDirectory.open(new File("Nag/index5"));
		
	} catch (IOException e1) {
		// TODO Auto-generated catch block
		e1.printStackTrace();
	}
	
	Directory dir[]={d1,d2};
	IndexWriter writer;
	{
	try
	{
		writer = new  IndexWriter(FSDirectory.open(new File("index")), new StandardAnalyzer(Version.LUCENE_CURRENT), true, new IndexWriter.MaxFieldLength(1000000));
		System.out.println("Merging...");
		writer.addIndexesNoOptimize(dir);
		System.out.println("optimizing..");
		writer.optimize();
		writer.close();
	
	}
	catch (CorruptIndexException e) 
	{
		e.printStackTrace();
	}
	catch (LockObtainFailedException e) 
	{
		e.printStackTrace();
	} 
	catch (IOException e) 
	{
		e.printStackTrace();
	}
	
	

	}
}
	public static void main(String[] args)
	{
		new MergeIndex();
	}
}